package com.zls.mapper;

import com.zls.pojo.Permission;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface PermissionMapper {
    @Results(id = "perMap",value = {
            @Result(column = "id",property = "id"),
            @Result(column = "path",property = "path"),
            @Result(column = "title",property = "title"),
            @Result(column = "link_url",property = "linkUrl"),
            @Result(column = "icon",property = "icon"),
            @Result(column = "parent_id",property = "parentId"),
            @Result(column = "id",property="children",many = @Many(select ="com.com.zls.mapper.PermissionMapper.selectById",fetchType = FetchType.EAGER))
    })
    @Select("Select * from permission where parent_id =0")
    List<Permission> findAll();

    @ResultMap("perMap")
    @Select("Select * from permission where parent_id =#{parent_id}")
    List<Permission> selectById(@Param("parent_id") Integer parent_id);
}
